package com.itcast.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itcast.health.pojo.PageResult;
import com.itcast.health.pojo.Permission;
import com.itcast.health.pojo.QueryPageBean;
import com.itcast.health.pojo.Result;
import com.itcast.service.PermissionService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author CM
 * @version v1.0
 * @date 2019/12/2 13:57
 * @description TODO
 **/
@RestController
@RequestMapping("permission")
public class PermissionController {
    @Reference
    private PermissionService permissionService;

    /**
     * 新增权限
     * @param permission
     * @return
     */
    @RequestMapping("add")
    public Result add(@RequestBody Permission permission) {
        try {
            permissionService.add(permission);
            return new Result(true, "新增权限成功");
        } catch (Exception e) {
            e.printStackTrace();
        return new Result(false,"新增权限失败");
        }
    }

    /**
     * 分页查询权限数据
     * @param queryPageBean
     * @return
     */
    @RequestMapping("findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        return permissionService.findPage(queryPageBean);
    }

    /**
     * 编辑权限数据
     * @param id
     * @return
     */
    @RequestMapping("edit")
    public Result edit(Integer id) {

        return permissionService.edit(id);
    }

    /**
     * 删除权限
     * @param id
     * @return
     */
    @RequestMapping("delete")
    public Result delete(Integer id) {

        return permissionService.delete(id);
    }

    /**
     * 更新权限数据
     * @param permission
     * @return
     */
    @RequestMapping("update")
    public Result update(@RequestBody Permission permission) {
        try {
            permissionService.update(permission);
            return new Result(true, "编辑成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "编辑失败");
        }
    }
}
